#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main()
{
    int s1[101], s2[101];
    int n1, n2, cnt1 = 0, cnt2 = 0, k;
    cin >> n1 >> n2;
    if (n1 > n2)
    {
        int temp = n1;
        n1 = n2;
        n2 = temp;
    }
    char c;
    while (cin >> c && c != 'T')
    {
        if (c == 'A')
        {
            cin >> k;
            if (cnt1 == n1 && cnt2)
                cout << "ERROR:Full\n";
            else if (cnt1 == n1)
            {
                while (cnt1)
                    s2[++cnt2] = s1[cnt1--];
                s1[++cnt1] = k;
            }
            else
                s1[++cnt1] = k;
        }
        else
        {
            if (!cnt2)
            {
                while (cnt1)
                    s2[++cnt2] = s1[cnt1--];
            }
            cout << s2[cnt2--] << endl;
        }
    }
}